import { netWork } from '@/network/request.js';

class Axios { // Axios请求构造类
  constructor () {
  }

  getRequst (url, params = null) { // GET请求函数
    return netWork({
      url,
      method: 'GET',
      params
    })
  }
  
  getPost (url, data = null) { // POST请求函数
    return netWork({
      url,
      method: 'POST',
      data
    })
  }

  getPut (url, params = null, data = null) { // PUT请求函数
    // console.log(url, params);
    return netWork({
      url,
      method: 'PUT',
      params,
      data
    })
  }

  getDel (url) {
    return netWork({
      url,
      method: 'DELETE'
    })
  }

}


function getAllRole () { // Home页面侧边栏请求
  return new Axios().getRequst('roles');
}

function postAddRole (data) { // 添加role
  return new Axios().getPost('roles', data);
}

function getUserInfoById (id) {
  return new Axios().getRequst(`roles/${id}`);
}

function putUserUpdateInfo (id, infoObj) {
  return new Axios().getPut(`roles/${id}`, null, infoObj);
}

function delUserId(id) {
  return new Axios().getDel(`roles/${id}`);
}

function delRemoveUserRight (roleId, rightId) {
  return new Axios().getDel(`roles/${roleId}/rights/${rightId}`);
}

function getRoleRightRequest () {
  return new Axios().getRequst('rights/tree');
}

function postUpdateRoleRight (roleId, rightStr) {
  return new Axios().getPost(`roles/${roleId}/rights`, {rids: rightStr});
}

export {
  getAllRole,
  postAddRole,
  getUserInfoById,
  putUserUpdateInfo,
  delUserId,
  delRemoveUserRight,
  getRoleRightRequest,
  postUpdateRoleRight
}


